<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 注意：项目正式环境请勿引用该地址 -->
    <link href="layui/css/layui.css" rel="stylesheet">
</head>
<body>


<script type="text/html" id="toolbarDemo">

    <button class="layui-btn layui-btn-sm" lay-event="insert" id="addUser"><i
            class="layui-icon">&#xe654;</i>新增
    </button>
    <button class="layui-btn layui-btn-sm" lay-event="deleteAll">批量删除</button>
    <div class="layui-inline" style="float:right;height:29px;" title="搜索" lay-event="search"><i
            class="layui-icon layui-icon-search"></i></div>
    <div style="width:645px;float:right;height:30px;">
        <div class="layui-inline layui-show-xs-block" style="left: -150px; ">
            <label class="layui-form-label layui-bg-gray" style="width: 110px;text-align: center">日期</label>
            <div class="layui-inline layui-show-xs-block">
                <input type="date" class="layui-input"  autocomplete="off" placeholder="日期" name="dealTime" id="dealTime">
            </div>
        </div>
        <label class="layui-form-label layui-bg-gray" style="right: -325px;width: 110px;text-align: center"></label>
        <input type="text" id="SecurityName" name="SecurityName" style="width:200px;float:right;height:30px;"
           placeholder="请输入"
           autocomplete="off" class="layui-input">
    </div>
</script>
<script type="text/html" id="Broker">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>


<!-- 注意：项目正式环境请勿引用该地址 -->
<script src="layui/layui.js"></script>


<script>
    layui.use(['table','form'], function(){
        var table = layui.table;
        var form = layui.form;
        var $ = layui.jquery;
        var layer = layui.layer;
        var laydate = layui.laydate;

        //温馨提示：默认由前端自动合计当前行数据。从 layui 2.5.6 开始： 若接口直接返回了合计行数据，则优先读取接口合计行数据。
        //详见：/docs/modules/table.html#totalRow
        table.render({
            height: 'full-55'
            , minLength: 80,
            elem: '#myTable'
            , id: 'tableId'
            , url: '/selectDealDataMap2'
            , toolbar: '#toolbarDemo'
            , title: '券商'
            , cols: [[
                {type: 'checkbox', field: 'left'}
                , {field: 'dealTime', title: '交易日期'}
                , {field: 'dealNumber', title: '交易数量'}
                , {field: 'dealPrice', title: '交易单价'}
                , {field: 'endMoney', title: '结算金额'}
                , {field: 'dealMoney', title: '交易金额'}
                , {field: 'endTime', title: '结算日期'}
                , {field: 'securityId', title: '现金账户'}
                , {field: 'securityName', title: '证券名称'}
                , {field: 'brokerName', title: '券商名称'}
                , {field: 'dealWay', title: '交易方式', templet: function (ExchangeRate) {
                        if (ExchangeRate.dealWay == 1) {
                            return '买入';
                        } else if (ExchangeRate.dealWay == 2) {
                            return '卖出';
                        }else if (ExchangeRate.dealWay == 3) {
                            return '分红';
                        }else if (ExchangeRate.dealWay == 4) {
                            return '送股';
                        }
                    }
                }
                , {field: 'dealState', title: '交易状态', templet: function (ExchangeRate) {
                        if (ExchangeRate.dealState == 1) {
                            return '已结算';
                        } else if (ExchangeRate.dealState == 2) {
                            return '未结算';
                        }
                    }}, {fixed: 'right', title: '操作', toolbar: '#Broker'}
            ]]
            , page: true
        });


        //工具栏事件
        table.on('toolbar(myTable2)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            switch (obj.event) {
                case 'getCheckData':
                    var data = checkStatus.data;

                    break;
                case 'getCheckLength':
                    var data = checkStatus.data;
                    layer.msg('选中了：' + data.length + ' 个');
                    break;
                case 'isAll':
                    layer.msg(checkStatus.isAll ? '全选' : '未全选')
                    break;
            }
            if (obj.event == 'insert') {
                //点击按钮的时候，弹出一个添加页面
                layer.open({
                    type: 2,
                    title: "添加",
                    content: "addDealData",
                    area: ['770px', '800px'],
                    //层销毁后触发
                    end: function () {
                        //刷新页面
                        table.reload('tableId');
                    }
                })

            }else if(obj.event=='search'){

                var dealTime=$("#dealTime").val();
                var SecurityName=$("#SecurityName").val();
                alert('gen'+dealTime)
                alert('gen'+SecurityName)
                //表格的重新加载事件
                table.reload('tableId', {
                    method: 'post'
                    , where: {
                        'dealTime': dealTime,
                        'SecurityName': SecurityName,
                    }
                    , page: {
                        curr: 1
                    }
                });
            }
        });
        table.on('tool(myTable2)', function (obj) {
            switch (obj.event) {
                case "del":
                    layer.confirm('您确定要删除吗', function (index) {
                        $.getJSON("deleteDealData"
                            , {dealId: obj.data.dealId}
                            , function (msg) {
                                if (msg === 1) {
                                    layer.close(index)
                                    table.reload('tableId');
                                }
                            })
                    })
                    break;
                case "edit":
                    layer.open({
                        type: 2,
                        title: "修改",
                        content: "updateDealData",
                        area: ['770px', '700px'],
                        success:function (layero,index) {
                            var body = layer.getChildFrame('body',index);
                            body.find("#dealId").val(obj.data.dealId);
                            body.find("#securityName").val(obj.data.securityName)
                            body.find("#brokerName").val(obj.data.brokerName);
                            body.find("#seatName").val(obj.data.seatName);
                            body.find("#fundName").val(obj.data.fundName);
                            body.find("#securityId").val(obj.data.securityId);
                            body.find("#seatId").val(obj.data.seatId);
                            body.find("#cashId").val(obj.data.cashId);
                            body.find("#fundId").val(obj.data.fundId);
                            body.find("#brokerId").val(obj.data.brokerId);
                            body.find("#dealTime").val(obj.data.dealTime);
                            body.find("#dealNumber").val(obj.data.dealNumber);
                            body.find("#dealPrice").val(obj.data.dealPrice);
                            body.find("#endTime").val(obj.data.endTime);
                            body.find("#endMoney").val(obj.data.endMoney);
                            body.find("#dealMoney").val(obj.data.dealMoney);
                            body.find("#commissionFees").val(obj.data.commissionFees);
                            body.find("#transferFee").val(obj.data.transferFee);
                            body.find("#stampDuty").val(obj.data.stampDuty);
                            body.find("#control").val(obj.data.control);
                            body.find("#handle").val(obj.data.handle);
                            body.find("#securityInterest").val(obj.data.securityInterest);
                            body.find("#dealWay").val(obj.data.dealWay);
                            body.find("#dealState").val(obj.data.dealState);
                        },
                        //层销毁后触发
                        end: function () {
                            //刷新页面
                            table.reload('tableId');
                        }
                    })
                    break;
            }
        })
    });
</script>
<table class="layui-hide" id="myTable" lay-filter="myTable2" ></table>
</body>
<script></script>
</html>